package me.zhengjie.common.utils.batchsave.vo

import cn.hutool.core.bean.BeanUtil
import cn.hutool.core.bean.copier.CopyOptions
import me.zhengjie.common.utils.JacksonUtil
import com.fasterxml.jackson.annotation.JsonTypeName
import org.apache.commons.lang3.builder.ToStringBuilder


@JsonTypeName("CallableResultVo")
data class CallableResultVo<T> (
    var result: List<T>? = null
){
    annotation class Update
    override fun toString(): String {
        val builder = ToStringBuilder(this)
        val fields = this.javaClass.declaredFields
        try {
            for (f in fields) {
                f.isAccessible = true
                builder.append(f.name, f[this]).append("\n")
            }
        } catch (e: Exception) {
            builder.append("toString builder encounter an error")
        }
        return builder.toString()
    }
    fun tojson(){
        JacksonUtil.toJSONString(this)
    }
    fun copy(source: CallableResultVo<List<T>>?) {
        BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true))
    }
}